package com.flyme.module.base.provider.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.base.client.entity.SysVipPrice;
import com.flyme.module.base.provider.service.SysVipPriceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * 会员价格配置管理
 *
 * @author zyf
 */
@Api(tags = "会员价格配置管理")
@RestController
@RequestMapping("/vipprice")
public class SysVipPriceController extends BaseController<SysVipPriceService, SysVipPrice> {


    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/list")
    public ResultBody list(@ModelAttribute PagerInfo pagerInfo, @ModelAttribute SysVipPrice vipPrice) {
        CriteriaQuery cq = new CriteriaQuery<EntityMap>(pagerInfo);
        cq.select("*, concat(vipTime, '个月') vipTimeA");
        cq.orderByAsc("sortOrder");
        PqGrid pqGrid = bizService.pageList(cq);
        return ResultBody.success(pqGrid);
    }

    @ApiOperation(value = "添加", notes = "添加")
    @PostMapping("/add")
    public ResultBody add(@ModelAttribute SysVipPrice vipPrice) {
        Boolean tag = bizService.save(vipPrice);
        return ResultBody.success("添加成功").setData(tag);
    }

    @ApiOperation(value = "更新", notes = "更新")
    @PostMapping("/update")
    public ResultBody update(@ModelAttribute SysVipPrice vipPrice) {
        Boolean tag = bizService.saveOrUpdate(vipPrice);
        return ResultBody.success("更新成功").setData(tag);
    }

    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/remove")
    public ResultBody remove(@RequestParam String[] ids) {
        Boolean tag = bizService.removeByIds(CollectionUtil.toList(ids));
        return ResultBody.success(tag);
    }

    @PostMapping("/get/{id}")
    public ResultBody get(@PathVariable Long id) {
        SysVipPrice vipPrice = bizService.getById(id);
        return ResultBody.success(vipPrice);
    }

}
